<?php

class Common_DataTable_Exporter {

    const EXPORT_CSV        = 'export.strategy.csv';
    const EXPORT_EXCEL      = 'export.strategy.excel';
    
    private $obj_datatable = null;

    public function __construct(Common_DataTable $obj_datatable) {
        $this->setDatatable($obj_datatable);
    }

    public function setDatatable(Common_DataTable $obj_datatable) {
        return $this->obj_datatable = $obj_datatable;
    }

    protected function getDatatable() {
        return $this->obj_datatable;
    }

    public function export($enm_type = null) {
    
        $str_export = null;
        
        switch($enm_type) {
        case self::EXPORT_CSV:
        default:
            $this->getDatatable()->switchView(new Common_DataTable_View_Csv());
            $str_export = $this->getDatatable()->render();
            
            break;
        }
        
        return $str_export;
    }
    
    /*
    public function download($str_name, $enm_type = null) {

        switch($enm_type) {
        case self::EXPORT_EXCEL:
            
            $obj_spreadsheet = Common_Spreadsheet_Factory::create();
            $obj_spreadsheet->insert_datatable($this->get_datatable(), array(
                'row_start' => 1
            ));
            
            $obj_spreadsheet->stream($str_name);
            
            break;
            
        case self::EXPORT_CSV:
        default:
            
            $str_export = $this->export($enm_type);

            $str_name = Common_Utility_DownloadFunctions::generate_filename($str_name, 'csv');
            
            Common_Utility_DownloadFunctions::set_headers('application/octet', $str_name);

            echo $str_export;
                        
            break;
        }
        
    }
    */
    
}
